package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	ProductEventNew           = "erp.ProductNew"
	ProductEventBeforeCreate  = "erp.ProductBeforeCreate"
	ProductEventBeforeUpdate  = "erp.ProductBeforeUpdate"
	ProductEventBeforeSave    = "erp.ProductBeforeCreate erp.ProductBeforeUpdate"
	ProductEventAfterCreate   = "erp.ProductAfterCreate"
	ProductEventAfterUpdate   = "erp.ProductAfterUpdate"
	ProductEventAfterSave     = "erp.ProductAfterCreate erp.ProductAfterUpdate"
	ProductEventDelete        = "erp.ProductDelete"
	ProductAccessControlEvent = "erp.ProductAccessControl"
)

func GetProductConfig() *mgo.DocConfig {
	return Product_Config
}

var Product_Config *mgo.DocConfig

func init() {
	Product_Config = NewProductConfig()
}
func NewProductConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "erp.Product",
		Fields: []string{
			"name", "fastName", "param", "code", "cat", "price", "unit", "isOn",
		},
		RelationFields: []string{
			"cat", "unit",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"cat": {
				Config:     GetProductCategoryConfig,
				DocName:    "ProductCategory",
				JoinType:   "O",
				KeyInside:  "catId",
				KeyOutSide: "id",
			},
			"unit": {
				Config:     GetUnitConfig,
				DocName:    "Unit",
				JoinType:   "O",
				KeyInside:  "unitId",
				KeyOutSide: "id",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
